"""
URL configuration for psychological_assessment_backend project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import path, include, re_path
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

# API文档配置
schema_view = get_schema_view(
    openapi.Info(
        title="SCL-90心理健康评估系统 API",
        default_version='v1',
        description="专业的SCL-90心理健康评估系统后端API\n\n"
                   "提供心理健康问卷数据处理、专业分析和结果分享功能。\n\n"
                   "主要功能:\n"
                   "- 用户基本信息收集\n"
                   "- SCL-90问卷处理（90道题目，1-5分评分）\n"
                   "- 专业心理分析（总分和平均分计算）\n"
                   "- 个性化报告生成\n"
                   "- 结果分享短链接\n\n"
                   "⚠️ 重要提醒：本系统仅供心理健康评估参考，不能替代专业医疗诊断。",
        terms_of_service="",
        contact=openapi.Contact(email="contact@example.com"),
        license=openapi.License(name="MIT License"),
    ),
    public=True,
    permission_classes=[permissions.AllowAny],
)

urlpatterns = [
    path("admin/", admin.site.urls),
    
    # API接口
    path("api/", include('assessment.urls', namespace='api')),
    
    # 短链接重定向（直接在根路径）
    re_path(r'^r/(?P<test_id>[^/]+)/', include('assessment.urls', namespace='redirect')),
    
    # API文档
    re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
    re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
    
    # 根路径
    path('', schema_view.with_ui('swagger', cache_timeout=0), name='api-docs'),
]
